package com.jy.oms.framework.asyn.task.alarm;

import com.jy.oms.framework.asyn.task.core.ExecutorContext;
import com.jy.oms.framework.util.WxRobotUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 企业微信告警
 *
 * @author liuquan
 */
public class WechatAlarmMessageService implements ITaskAlarmMessageService {
    private static Logger logger = LoggerFactory.getLogger(WechatAlarmMessageService.class);
    private String noticeWechatKey;

    public WechatAlarmMessageService(String noticeWechatKey) {
        this.noticeWechatKey = noticeWechatKey;
    }

    @Override
    public void alarm(AlarmMessage alarmMessage) {
        if (ExecutorContext.isDev()) {
            logger.error(alarmMessage.toString());
        } else {
            if (StringUtils.isNotBlank(noticeWechatKey)) {
                WxRobotUtils.sendMarkdownMsg(noticeWechatKey, alarmMessage.toString());
            }
        }
    }

}
